import { reqCategoryListData,reqBannerListData,reqFloorListData } from '@/api'
const state = {
    categoryList: [],
    bannerListData:[],
    floorListData:[]
}

const actions = {
    // 获取三级分类列表数据
    async getCategoryListData(store){
        console.log('发起请求获取三级分类列表数据');
        const result = await reqCategoryListData()
        if(result.code === 200){
            //判断数据是否获取成功，如果成功则交给mutations中的方法
            store.commit('GET_CATEGORY_LIST_DATA',result)
        }else{
            //如果获取失败，则打印失败的信息
            console.log(result.message);
        }
    },
    //获取banner轮播图的数据
    async getBannerListData({commit}){
        const result = await reqBannerListData()
        if(result.code === 200){
            commit('UPDATE_BANNER_LIST_DATA',result)
        }else{
            console.log(result.message);
        }
    },
    //获取floor的数据
    async getFloorListData({commit}){
        const result = await reqFloorListData()
        console.log(result,'floorResult');
        if(result.code === 200){
            commit('UPDATE_FLOOR_LIST_DATA',result.data)
        }else{
            console.log('获取floor数据失败');
        }
    }
}

const getters = {}
const mutations = {
    GET_CATEGORY_LIST_DATA(state,payload){
        state.categoryList = payload.data
    },
    //更新banner轮播图的数据
    UPDATE_BANNER_LIST_DATA(state,payload){
        state.bannerListData = payload.data
        console.log('state.bannerListData',state.bannerListData);
    },
    //更新floor的数据
    UPDATE_FLOOR_LIST_DATA(state,payload){
        state.floorListData = payload
        console.log(state.floorListData,'state.floorListData');
    }
}

export default {
    namespaced:true, //分模块一定要开启命名空间
    state,
    actions,
    getters,
    mutations
}